package cmm.Parser;

import cmm.Lexer.TokenType;

import java.util.LinkedList;

/**
 * Created by zhangzheyu on 2017/10/27.
 */
public class TreeNode {
    private NodeType type;
    private LinkedList<TreeNode> childnodes = new LinkedList<TreeNode>();
    private TokenType dataType;
    private  String value;
    private  TreeNode mNext;
    private TreeNode father;
    public TreeNode(NodeType type){
        super();
        this.type = type;
        if (this.type == NodeType.FACTOR||this.type== NodeType.LITREAL){
            this.dataType = TokenType.PLUS;
        }
    }
    public TreeNode(NodeType type, TokenType tokenType, String value){
        this.type =type;
        this.dataType = tokenType;
        this.value =value;
    }
    public void setFather(TreeNode father){
        this.father =father;
    }
    public TreeNode getFather(){
        return father;
    }

    public NodeType getType(){
        return type;
    }
    public void setType(NodeType type){
        this.type = type;
    }
    public void addtoChildnode(TreeNode node,TreeNode father){
        childnodes.add(node);
        node.father = father;
    }
    public  TreeNode getNext(){
        return mNext;
    }
    public void setNext(TreeNode mNext){
        this.mNext = mNext;
    }
    public TokenType getDataType() {
        return dataType;
    }
    public void setDataType(TokenType type) {
        this.dataType = type;
    }
    public String getValue() {
        return value;
    }
    public void setValue(String value) {
        this.value = value;
    }
    public LinkedList<TreeNode> getChildnodes(){
        return childnodes;
    }

    public String toString() {
        return "NodeType type: " + type + ",  TokenType dataType" +  dataType + ",  value" + value + ", childrenNum "+ childnodes.size();
    }
}
